package lily.phs.object;

import lily.phs.database.Constants;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;


public class ModuleSelect implements Constants{
	private static final String[] PROJECTION=new String[]{
		MOSE_PROFILE_ID
	};
	private Context myContext;
	private int mose_profile_id=-1;
	private int mose_health_record_id=-1;
	private int mose_vaccinate_id=-1;
	private int mose_0_6_child_health_id=-1;
	private int mose_maternal_health_id=-1;
	private int mose_olds_id=-1;
	private int mose_hypertension_id=-1;
	private int mose_diabet2_id=-1;
	private int mose_mental_id = -1;

	public ModuleSelect(Context context){
		this.myContext=context;
	} 
	
	
	public int getMose_profile_id() {
		return mose_profile_id;
	}


	public void setMose_profile_id(int mose_profile_id) {
		this.mose_profile_id = mose_profile_id;
	}


	public int getMose_health_record_id() {
		return mose_health_record_id;
	}


	public void setMose_health_record_id(int mose_health_record_id) {
		this.mose_health_record_id = mose_health_record_id;
	}


	public int getMose_vaccinate_id() {
		return mose_vaccinate_id;
	}


	public void setMose_vaccinate_id(int mose_vaccinate_id) {
		this.mose_vaccinate_id = mose_vaccinate_id;
	}


	public int getMose_0_6_child_health_id() {
		return mose_0_6_child_health_id;
	}


	public void setMose_0_6_child_health_id(int mose_0_6_child_health_id) {
		this.mose_0_6_child_health_id = mose_0_6_child_health_id;
	}


	public int getMose_maternal_health_id() {
		return mose_maternal_health_id;
	}


	public void setMose_maternal_health_id(int mose_maternal_health_id) {
		this.mose_maternal_health_id = mose_maternal_health_id;
	}


	public int getMose_olds_id() {
		return mose_olds_id;
	}


	public void setMose_olds_id(int mose_olds_id) {
		this.mose_olds_id = mose_olds_id;
	}


	public int getMose_hypertension_id() {
		return mose_hypertension_id;
	}


	public void setMose_hypertension_id(int mose_hypertension_id) {
		this.mose_hypertension_id = mose_hypertension_id;
	}


	public int getMose_diabet2_id() {
		return mose_diabet2_id;
	}


	public void setMose_diabet2_id(int mose_diabet2_id) {
		this.mose_diabet2_id = mose_diabet2_id;
	}


	public int getMose_mental_id() {
		return mose_mental_id;
	}


	public void setMose_mental_id(int mose_mental_id) {
		this.mose_mental_id = mose_mental_id;
	}


	public void insertModuleSelect(){
		ContentValues value;
		value=new ContentValues();
		value.put(MOSE_PROFILE_ID, this.getMose_profile_id());
	    value.put(MOSE_HEALTH_RECORD_ID, this.getMose_health_record_id());
	    value.put(MOSE_VACCINATE_ID, this.getMose_vaccinate_id());
	    value.put(MOSE_0_6_CHILD_HEALTH_ID, this.getMose_0_6_child_health_id());
	    value.put(MOSE_MATERNAL_HEALTH_ID, this.getMose_maternal_health_id());
	    value.put(MOSE_MENTAL_ID, this.getMose_mental_id());
	    value.put(MOSE_DIABET2_ID, this.getMose_diabet2_id());
	    value.put(MOSE_HYPERTENSION_ID, this.getMose_hypertension_id());
	    value.put(MOSE_OLDS_ID, this.getMose_olds_id());
		myContext.getContentResolver().insert(Constants.CONTENT_URI_TB2, value);
		
	}
	public void selectModuleSelect(int pro){
		Cursor cur = myContext.getContentResolver().query(CONTENT_URI_TB2, null,
				MOSE_PROFILE_ID + "=" + pro + "", null, null);
		System.out.println("cur.getCount="+cur.getCount());
		while(cur.moveToNext()){
			this.mose_profile_id = cur.getInt(cur.getColumnIndex(Constants.MOSE_PROFILE_ID));
			this.mose_health_record_id = cur.getInt(cur.getColumnIndex(Constants.MOSE_HEALTH_RECORD_ID));
			this.mose_vaccinate_id=cur.getInt(cur.getColumnIndex(Constants.MOSE_VACCINATE_ID));
			this.mose_0_6_child_health_id=cur.getInt(cur.getColumnIndex(Constants.MOSE_0_6_CHILD_HEALTH_ID));
			this.mose_maternal_health_id=cur.getInt(cur.getColumnIndex(Constants.MOSE_MATERNAL_HEALTH_ID));
			this.mose_mental_id = cur.getInt(cur.getColumnIndex(Constants.MOSE_MENTAL_ID));
			this.mose_diabet2_id = cur.getInt(cur.getColumnIndex(MOSE_DIABET2_ID));
			this.mose_hypertension_id = cur.getInt(cur.getColumnIndex(MOSE_HYPERTENSION_ID));
			this.mose_olds_id = cur.getInt(cur.getColumnIndex(MOSE_OLDS_ID));
		}	
		cur.close();
	}
	
	public void updateModuleSelect(int pro){
		ContentValues value;
		value=new ContentValues();
	    value.put(Constants.MOSE_HEALTH_RECORD_ID, this.getMose_health_record_id());
	    value.put(Constants.MOSE_VACCINATE_ID, this.getMose_vaccinate_id());
	    value.put(Constants.MOSE_0_6_CHILD_HEALTH_ID, this.getMose_0_6_child_health_id());
	    value.put(Constants.MOSE_MATERNAL_HEALTH_ID, this.getMose_maternal_health_id());
	    value.put(Constants.MOSE_MENTAL_ID, this.getMose_mental_id());
	    value.put(MOSE_DIABET2_ID, this.getMose_diabet2_id());
	    value.put(MOSE_HYPERTENSION_ID, this.getMose_hypertension_id());
	    value.put(MOSE_OLDS_ID, this.getMose_olds_id());
		myContext.getContentResolver().update(CONTENT_URI_TB2, value, 
				MOSE_PROFILE_ID + "=" + pro + "", null);
	}
	
	public void selectNameAndCode(int pro){
		Cursor cur = myContext.getContentResolver().query(CONTENT_URI_TB2, PROJECTION,
				MOSE_PROFILE_ID + "=" + pro + "", null, null);
		System.out.println("cur.getCount="+cur.getCount());
		while(cur.moveToNext()){
			this.mose_profile_id = cur.getInt(cur.getColumnIndex(MOSE_PROFILE_ID));
		//	this.heti_name = cur.getString(cur.getColumnIndex(HETI_NAME));
			break;
		}
		cur.close();
	}
	
	public void deleteModuleSelect(int pro){
		myContext.getContentResolver().delete(CONTENT_URI_TB2, MOSE_PROFILE_ID + "=" + pro + "", null);
	}
}
